package ltd.hanamaki.review.jdbc.jdbctest;

import ltd.hanamaki.review.jdbc.util.JDBCUtils;
import ltd.hanamaki.review.jdbc.util.JDBCUtils_1;
import ltd.hanamaki.review.jdbc.util.JDBCUtils_DBCP;

import java.sql.*;

public class JDBCUtilsDbcp {

    static Connection connection;
    static Statement statement;
    static ResultSet resultSet;


    public static void main(String[] args) {
        query();

    }

    /* 数据库查询 */
    public static void query() {
        connection = JDBCUtils_DBCP.getCon();
        /* 创建sql 的查询 对象  statement */
        try {
            statement = connection.createStatement();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        /* 编写 sql语句 */
        String sql = "select * from students";

        try {
            resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                System.out.println(resultSet.getObject(2));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.release(connection, statement, resultSet, null);
        }

    }

}
